﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using System.Text;
using PowerCreator.LMS.Web.Question;
using PowerCreator.LMS.Question.Entiry;
using PowerCreator.LMS.Common.Script;


public partial class sysadmin_QuestionManager_CombinationQuestion_Add_danx : PowerCreator.LMS.Web.Base.BasePage
{
    ManagerQuestion objQuestion = new ManagerQuestion();
    protected void Page_Load(object sender, EventArgs e)
    {
        //if (!GetRole(Role.AddQuestion))
        //{
        //    Script.ShowAndHistory("您没有添加试题的权限!", -1);
        //    return;
        //}
        if (!IsPostBack)
        {

            ViewState["QuestionID"] = Request.QueryString["QuestionID"].ToString();
            ViewState["Question_Father"] = objQuestion.LoadQuestion(int.Parse(ViewState["QuestionID"].ToString()));
            //ViewState["FKQuestionCourseID"] = Base64.Decode(Request.QueryString["CourseID"].ToString());
            //ViewState["QuestionDefaultScore"] = Base64.Decode(Request.QueryString["Score"].ToString());
            //ViewState["QuestionKen"] = Base64.Decode(Request.QueryString["Ken"].ToString());
            //ViewState["QuestionState"] = Base64.Decode(Request.QueryString["State"].ToString());
            //ViewState["QuestionDiffculty"] = Base64.Decode(Request.QueryString["Diffculty"].ToString());
            ViewState["TypeID"] = 2;
            bandList(3);
            ViewState["UserID"] = 10000;
            InitPage();
        }
    }


    protected override void InitPage()
    {

        lab_TitleInfo.Text = GetLanageValueByKey("lab_AddQuestionInfo_danx_ContentTitle", PowerCreator.LMS.Language.LanagetItemType.Page);
        lab_QuestionCount.Text = GetLanageValueByKey("lab_AddQuestionInfo_danx_QuestionContent", PowerCreator.LMS.Language.LanagetItemType.Page);
        lab_QuestionOption.Text = GetLanageValueByKey("lab_AddQuestionInfo_danx_QuestionOption", PowerCreator.LMS.Language.LanagetItemType.Page);
        lab_RightAnswer.Text = GetLanageValueByKey("lab_AddQuestionInfo_danx_RightAnswer", PowerCreator.LMS.Language.LanagetItemType.Page);

        btn_Save.Text = GetLanageValueByKey("btn_Save", PowerCreator.LMS.Language.LanagetItemType.Page);
        

        btn_AddOptionC.Text = GetLanageValueByKey("btn_AddQuestionInfo_danx_AddOption", PowerCreator.LMS.Language.LanagetItemType.Page);
        btn_AddOptionD.Text = GetLanageValueByKey("btn_AddQuestionInfo_danx_AddOption", PowerCreator.LMS.Language.LanagetItemType.Page);
        btn_AddOptionE.Text = GetLanageValueByKey("btn_AddQuestionInfo_danx_AddOption", PowerCreator.LMS.Language.LanagetItemType.Page);
        base.InitPage();
    }
    private void bandList(int ItemCount)
    {
        ListItem objlist;
        for (int i = 0; i < ItemCount; i++)
        {
            objlist = new ListItem();
            switch (i)
            {
                case 0: objlist.Text = "A";
                    objlist.Selected = true;
                    break;
                case 1: objlist.Text = "B";
                    break;
                case 2: objlist.Text = "C";
                    break;
                case 3: objlist.Text = "D";
                    break;
                case 4: objlist.Text = "E";
                    break;
                case 5: objlist.Text = "F";
                    break;
            }
            objlist.Value = i.ToString();

            rbtn_answer.Items.Add(objlist);
        }
    }

    private string ConvertOptionID(int Index)
    {
        string OptionID = string.Empty;
        switch (Index)
        {
            case 0: OptionID = "A";
                break;
            case 1: OptionID = "B";
                break;
            case 2: OptionID = "C";
                break;
            case 3: OptionID = "D";
                break;
            case 4: OptionID = "E";
                break;
            case 5: OptionID = "F";
                break;
        }
        return OptionID;
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        VOQuestion voQuestion_Father = new VOQuestion();
        voQuestion_Father = (VOQuestion)ViewState["Question_Father"];
        VOQuestion voQuestion = new VOQuestion();
        voQuestion.QuestionIsFather = 0;
        voQuestion.FKQuestionCourseID = voQuestion_Father.FKQuestionCourseID;
        voQuestion.QuestionCreateID = int.Parse(ViewState["UserID"].ToString());

        voQuestion.QuestionCreateTime = DateTime.Now;

        voQuestion.QuestionAnswer = rbtn_answer.SelectedItem.Text;
        voQuestion.QuestionDefaultScore = voQuestion_Father.QuestionDefaultScore;
        voQuestion.QuestionDiffculty = voQuestion_Father.QuestionDiffculty;
        voQuestion.QuestionKen = voQuestion_Father.QuestionKen;


        

        voQuestion.QuestionClass = 3;
        voQuestion.QuestionContent = txtQuestionContent.Value;
        voQuestion.QuestionParse = "";
        voQuestion.FKQuestionTypeID = int.Parse(ViewState["TypeID"].ToString());
        voQuestion.QuestionState = voQuestion_Father.QuestionState;         //禁用1,启用2

        ArrayList list = new ArrayList();

        ArrayList Optionlist = new ArrayList();
        Optionlist.Add(txt_OptionA.Text.Trim());
        Optionlist.Add(txt_OptionB.Text.Trim());
        Optionlist.Add(txt_OptionC.Text.Trim());
        Optionlist.Add(txt_OptionD.Text.Trim());
        Optionlist.Add(txt_OptionE.Text.Trim());
        Optionlist.Add(txt_OptionF.Text.Trim());


        for (int i = 0; i < rbtn_answer.SelectedIndex + 1; i++)
        {
            string OptionID = ConvertOptionID(i);

            if (Optionlist[i].ToString() == "")
            {
                Script.Alert(Page, "msg", OptionID + GetLanageValueByKey("msg_AddQuestionInfo_checkmsg2", PowerCreator.LMS.Language.LanagetItemType.Page));
                return;
            }
        }
        for (int i = 0; i < Optionlist.Count; i++)
        {
            string OptionID = ConvertOptionID(i);
            if (Optionlist[i].ToString() != "")
            {
                list.Add(OptionID + "、" + Optionlist[i].ToString());
            }
        }
        try
        {
            int questionID=0;
            if (objQuestion.CreateQuestionOptionList(voQuestion, list, ref questionID))
            {
                if (voQuestion_Father.QuestionItemList != "")
                {
                    voQuestion_Father.QuestionItemList = voQuestion_Father.QuestionItemList + "$" + questionID.ToString();
                }
                else
                {
                    voQuestion_Father.QuestionItemList = questionID.ToString();
                }
                if (objQuestion.UpdateQuetion(voQuestion_Father))
                {
                    Script.Alert(GetLanageValueByKey("Msg_ManagerQuestion_WorkOK", PowerCreator.LMS.Language.LanagetItemType.Page));
                    Script.ReloadParent();
                    Script.CloseMe();
                }


               
            }
            else
            {
                Script.Alert(GetLanageValueByKey("Msg_ManagerQuestion_WorkNo", PowerCreator.LMS.Language.LanagetItemType.Page));
            }


           
            //Script.ShowAndRedirect(this, "操作成功", "ManagerQuestionInfo.aspx");
        }
        catch
        {
            //Script.ShowAndRedirect(this, "操作失败", "ManagerQuestionInfo.aspx");
            Script.Alert(GetLanageValueByKey("Msg_ManagerQuestion_WorkNo", PowerCreator.LMS.Language.LanagetItemType.Page));
        }

    }


    protected void btn_AddOptionC_Click(object sender, EventArgs e)
    {
        ListItem objlist = new ListItem();
        objlist.Text = "D";
        objlist.Value = "3";
        rbtn_answer.Items.Add(objlist);
        Pnl_D.Visible = true;
        btn_AddOptionC.Visible = false;
    }
    protected void btn_AddOptionD_Click(object sender, EventArgs e)
    {
        ListItem objlist = new ListItem();
        objlist.Text = "E";
        objlist.Value = "4";
        rbtn_answer.Items.Add(objlist);
        Pnl_E.Visible = true;
        btn_AddOptionD.Visible = false;
    }
    protected void btn_AddOptionE_Click(object sender, EventArgs e)
    {
        ListItem objlist = new ListItem();
        objlist.Text = "F";
        objlist.Value = "5";
        rbtn_answer.Items.Add(objlist);
        Pnl_F.Visible = true;
        btn_AddOptionE.Visible = false;
    }

}
